package DynamicProgramming;

public class p416 {
    class Solution {
        public boolean canPartition(int[] nums) {
            int sum = 0;
            for (int k : nums) {//背包容量为sum/2
                sum += k;
            }
            if(sum % 2 != 0)    return false;
            int capacity = sum / 2;
            int[] dp =new int[capacity + 1];
            dp[0] = 0;
            for (int num : nums) {//遍历物品
                for (int j = capacity; j >= num; j--) {//背包
                    dp[j] = Math.max(dp[j], dp[j - num] + num);
                }
            }
            return dp[capacity] == capacity;
        }
    }
}
